package sys.utils;

import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.models.auth.In;
import sys.entity.RoleEntity;

import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test2 {
    public static void main(String[] args) {
        List<RoleEntity> list = new ArrayList<>();

        RoleEntity roleEntity = new RoleEntity();
        roleEntity.setId(1);
        roleEntity.setSex("男");
        roleEntity.setRoleName("总经理");

        RoleEntity roleEntity2 = new RoleEntity();
        roleEntity2.setId(2);
        roleEntity2.setSex("女");
        roleEntity2.setRoleName("财务部部长");


        RoleEntity roleEntity3 = new RoleEntity();
        roleEntity3.setId(3);
        roleEntity3.setSex("男");
        roleEntity3.setRoleName("程序员");


        list.add(roleEntity);
        list.add(roleEntity2);
        list.add(roleEntity3);

       /* List<String> roleNameList = new ArrayList<>();
        //获取角色的名字
        for (RoleEntity roleEntity1 : list) {
            roleNameList.add(roleEntity1.getRoleName());

        }*/

        List<Integer> roleNameList = list.stream().map(RoleEntity::getId).collect(Collectors.toList());
        System.out.println(roleNameList);
        long count = list.stream().filter(roleEntity1 -> roleEntity1.getSex() == "男").count();
        System.out.println(count);
        List<RoleEntity> collect = list.stream().limit(2).collect(Collectors.toList());
        System.out.println(collect);
        RoleEntity role = null;
        Optional<RoleEntity> role1 = Optional.ofNullable(role);
        if (role1.isPresent()) {
            System.out.println("对象不为空");
        }
        if (role == null) {

        }


    }
}
